package com.wayhome.srpingbootmybatis.controller.excel;

import com.wayhome.srpingbootmybatis.excel.CaseEntityExcel;
import com.wayhome.srpingbootmybatis.excel.CaseListExcel;
import com.wayhome.srpingbootmybatis.excel.TldyFormReport;
import com.wayhome.srpingbootmybatis.utils.ExcelUtil;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping(value = "/tldy/excel")
public class TldyExcelController {

    @PostMapping(value = "exportTldyAudit")
    public void exportTldyAudit(HttpServletResponse response){

        //主导出列表
        TldyFormReport tldyFormReport = new TldyFormReport();
        tldyFormReport.setFixmedinsName("曲阳县中医院");

        //病例信息
        List<CaseListExcel> list = new ArrayList<>();
        CaseListExcel caseListExcel = new CaseListExcel();
        caseListExcel.setAuditStep("已结束");

        CaseEntityExcel caseEntityExcel = new CaseEntityExcel();
        caseEntityExcel.setPsnName("严江");
        caseEntityExcel.setCheckExpertName("李穆芝，张馨冉，杨青幡");
        caseEntityExcel.setRecheckExpertName("高裕民，冯广智，王星");
//        caseListExcel.setCaseEntityExcel(caseEntityExcel);
        caseListExcel.setCaseEntityExcel(Collections.singletonList(caseEntityExcel));



        CaseListExcel caseListExcel2 = new CaseListExcel();
        CaseEntityExcel caseEntityExcel2 = new CaseEntityExcel();
        caseEntityExcel2.setPsnName("严江");
        caseEntityExcel2.setCheckExpertName("李穆芝，张馨冉，杨青幡");
        caseEntityExcel2.setRecheckExpertName("高裕民，冯广智，王星");
//        caseListExcel2.setCaseEntityExcel(caseEntityExcel2);
        caseListExcel2.setCaseEntityExcel(Collections.singletonList(caseEntityExcel2));


//        list.add(caseListExcel);
//        list.add(caseListExcel2);
        List<CaseEntityExcel> entityExcelList = new ArrayList<>();
        entityExcelList.add(caseEntityExcel2);
        entityExcelList.add(caseEntityExcel);

        tldyFormReport.setList(entityExcelList);

        List<TldyFormReport> reportList = new ArrayList<>();
        reportList.add(tldyFormReport);

        ExcelUtil.exportExcel(reportList, "保定市特例单议日报表(二)","sheet1", TldyFormReport.class, "特例单议日报表（二）", response);
    }

}
